package com.jeesite.modules.banrecord.web;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.banrecord.entity.BanRecord;
import com.jeesite.modules.banrecord.service.BanRecordService;

/**
 * banrecordController
 * @author k
 * @version 2025-08-21
 */
@Controller
@RequestMapping(value = "${adminPath}/banrecord/banRecord")
public class BanRecordController extends BaseController {

	@Autowired
	private BanRecordService banRecordService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public BanRecord get(Long tid, boolean isNewRecord) {
		return banRecordService.get(tid, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("banrecord:banRecord:view")
	@RequestMapping(value = {"list", ""})
	public String list(BanRecord banRecord, Model model) {
		model.addAttribute("banRecord", banRecord);
		return "modules/banrecord/banRecordList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("banrecord:banRecord:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<BanRecord> listData(BanRecord banRecord, HttpServletRequest request, HttpServletResponse response) {
		banRecord.setPage(new Page<>(request, response));
		Page<BanRecord> page = banRecordService.findPage(banRecord);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("banrecord:banRecord:view")
	@RequestMapping(value = "form")
	public String form(BanRecord banRecord, Model model) {
		model.addAttribute("banRecord", banRecord);
		return "modules/banrecord/banRecordForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("banrecord:banRecord:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated BanRecord banRecord) {
		banRecordService.save(banRecord);
		return renderResult(Global.TRUE, text("保存banrecord成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("banrecord:banRecord:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(BanRecord banRecord) {
		banRecordService.delete(banRecord);
		return renderResult(Global.TRUE, text("删除banrecord成功！"));
	}
	
}